
public class HtmlLite {

	public static String clean( String mess ) {
		
		String clean = "";
		
		mess = mess.replace("\n", "");
		mess = mess.replace("  ", " ");
		mess = mess.replace("\t", "");
		
		// regex to get '<p>' and '<p id="whatever">' both
		String regex = "<p[^>]*>";
		String replacement = "\n\n   ";// replace '<p*>' w/ '\n\n\t' 
		clean = mess.replaceAll(regex, replacement);
		
		regex = "</p[^>]*>";
		replacement = "";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		
		// h1
		regex = "<h1[^>]*>";
		replacement = "\n\n=";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		regex = "</h1[^>]*>";
		replacement = "=";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		
		// h2
		regex = "<h2[^>]*>";
		replacement = "\n\n-=";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		regex = "</h2[^>]*>";
		replacement = "=-";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		
		// h3
		regex = "<h3[^>]*>";
		replacement = "\n\n-==";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		regex = "</h3[^>]*>";
		replacement = "==-";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		
		// a
		regex = "<a[^>]*>";
		replacement = "[_"; 
		clean = clean.replaceAll(regex, replacement);
		regex = "</a[^>]*>";
		replacement = "_]"; 
		clean = clean.replaceAll(regex, replacement);
		
		// ul
		regex = "<ul[^>]*>";
		replacement = "\n"; 
		clean = clean.replaceAll(regex, replacement);
		regex = "</ul[^>]*>";
		replacement = ""; 
		clean = clean.replaceAll(regex, replacement);
		
		// li
		regex = "<li[^>]*>";
		replacement = "\n   *"; 
		clean = clean.replaceAll(regex, replacement);
		regex = "</li[^>]*>";
		replacement = ""; 
		clean = clean.replaceAll(regex, replacement);
		
		// div
		regex = "<div[^>]*>";
		replacement = "\n"; 
		clean = clean.replaceAll(regex, replacement);
		regex = "</div[^>]*>";
		replacement = ""; 
		clean = clean.replaceAll(regex, replacement);
		
		// strong
		regex = "<strong[^>]*>";
		replacement = "|";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		regex = "</strong[^>]*>";
		replacement = "|";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		
		// i
		regex = "<i[^>]*>";
		replacement = "/";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		regex = "</i[^>]*>";
		replacement = "/";// replace '</p*>' w/ '' 
		clean = clean.replaceAll(regex, replacement);
		
		return clean;
	}
}
